<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%
    String basePath = request.getScheme() + "://" +
            request.getServerName() + ":" + request.getServerPort() +
            request.getContextPath() + "/";
%>
<html>
<head>
    <title>Title</title>
    <base href="<%=basePath%>">
    <script type="text/javascript" src="static/js/jquery-3.4.1.js"></script>
    <script type="text/javascript">
        $(function () {
            $("#commitBtn").click(function () {
                if ($("#content").val().trim()==="" || $("#category").val().trim()==="" ||
                    $("#oldPrice").val().trim()==="" || $("#price").val().trim()==="" ||
                    $("#nums").val().trim()==="") {
                    alert("编辑物品失败，请确定物品信息是否填写完整！")
                } else if (isNaN($("#oldPrice").val().trim()) || isNaN($("#price").val().trim())) {
                    alert("请正确填写价格")
                } else if (parseInt($("#nums").val().trim())!= $("#nums").val().trim()) {
                    alert("物品数量必须是整数")
                } else {
                    var data = $("#commitForm").serialize();
                    $.ajax({
                        type: "post",
                        url: "product/modifyProduct",
                        dataType: "text",
                        data: data,
                        success: function (resp) {
                            alert(resp)
                        }
                    })
                }
            })
        })
    </script>
</head>
<body>
<div style="padding: 16px; background-color: #f5f5f5; color: #777777">
    ${product.content} / 编辑物品
</div>
<div align="center" style="margin-top: 30px">
    <form id="commitForm">
        <table style="line-height: 30px; width: 400px;
            border: 1px solid #faebcc">
            <tr style="color: #8a6d3b;
                           background-color: #fcf8e3;
                           border: 1px solid #faebcc;"
                align="center">
                <td colspan="2">编辑物品</td>
            </tr>
            <tr align="center" style="line-height: 32px">
                <td>物品内容</td>
                <td>
                    <input type="hidden" id="productId" name="id" value="${product.id}">
                    <input type="text" id="content" name="content" value="${product.content}">
                </td>
            </tr>
            <tr align="center" style="line-height: 32px">
                <td>物品类别</td>
                <td><input type="text"  id="category" name="category" value="${product.category}"></td>
            </tr>
            <tr align="center" style="line-height: 32px">
                <td>原价格</td>
                <td><input type="text" id="oldPrice" name="oldPrice" value="${product.oldPrice}"></td>
            </tr>
            <tr align="center" style="line-height: 32px">
                <td>优惠价格</td>
                <td><input type="text" id="price" name="price" value="${product.price}"></td>
            </tr>
            <tr align="center" style="line-height: 32px">
                <td>库存数量</td>
                <td><input type="text" id="nums" name="nums" value="${product.nums}"></td>
            </tr>
            <tr style="line-height: 60px">
                <td colspan="2" align="center">
                    <input type="button" id="commitBtn" style="
                          color: #fff; width: 80px; margin: 10px;
                          background-color: #5cb85c;
                          border-color: #4cae4c;
                          font-size: 18px;
                          font-weight: 400;
                          display: inline-block;
                          padding: 6px 12px;cursor: pointer;" value="提交">
                </td>
            </tr>
        </table>
    </form>
</div>
</body>
</html>
